<%--@elvariable id="webRoot" type="com.doupi.partner.op.interceptor.OpFilter"--%>
<%--@elvariable id="CURRENT_USER" type="com.doupi.partner.manager.authenticator.filter.CaptchaAuthenticationFilter.onLoginSuccess"--%>
<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="common/tags.jsp" %>

<!doctype html>
<html class="no-js">
<head>
    <jsp:include page="common/assets.jsp"></jsp:include>
</head>
<body>
<jsp:include page="common/header.jsp"></jsp:include>

<div class="am-cf admin-main">
    <!-- sidebar start -->
    <jsp:include page="common/menu.jsp"></jsp:include>
    <!-- sidebar end -->

    <!-- content start -->
    <div class="admin-content">
        <div class="am-cf am-padding">
            <div class="am-fl am-cf">
                <strong class="am-text-primary am-text-lg">修改密码</strong>
            </div>
        </div>
        <hr/>
        <div class="am-g">
            <div class="am-u-sm-12 am-u-md-8">
                <form class="am-form am-form-horizontal" action="${webRoot}/doUpdatePassword">
                    <div class="am-form-group">
                        <label for="old-password" class="am-u-sm-3 am-form-label">旧密码</label>
                        <div class="am-u-sm-9">
                            <input type="password" id="old-password" placeholder="输入你的旧密码" value="">
                        </div>
                    </div>

                    <div class="am-form-group">
                        <label for="new-password" class="am-u-sm-3 am-form-label">新密码</label>
                        <div class="am-u-sm-9">
                            <input type="password" id="new-password" placeholder="输入你的新密码">
                        </div>
                    </div>

                    <div class="am-form-group">
                        <label for="confirm-password" class="am-u-sm-3 am-form-label">确认密码</label>
                        <div class="am-u-sm-9">
                            <input type="password" id="confirm-password" placeholder="请输入确认密码">
                        </div>
                    </div>

                    <div class="am-form-group">
                        <div class="am-u-sm-9 am-u-sm-push-3">
                            <button type="button" class="am-btn am-btn-primary" id="submit-button">保存修改</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>
</div>

<jsp:include page="common/footer.jsp"></jsp:include>

<script type="text/javascript">
    $(document).ready(function () {
        $('#submit-button').click(function () {
            var oldPassword = $.trim($('#old-password').val());
            var newPassword = $.trim($('#new-password').val());
            var confirmPassword = $.trim($('#confirm-password').val());

            if (oldPassword == '') {
                layer.warn('请您旧密码');
                return false;
            }

            if (newPassword == '') {
                layer.warn('请您填写新密码');
                return false;
            }

            if (newPassword == oldPassword) {
                layer.warn('新密码和旧密码相同，不用修改');
                return false;
            }

            if (newPassword != confirmPassword) {
                layer.warn('新密码和确认密码不相同，请确认后修改');
                return false;
            }

            ajaxRequest({
                url: "${webRoot}/doUpdatePassword",
                data: {
                    oldPassword: oldPassword,
                    newPassword: newPassword
                }
            }, function () {
                location.href = '${webRoot}/logout?jid=<%=session.getId()%>';
            });
        });
        $('#old-password').val('');
        $('#new-password').val('');
        $('#confirm-password').val('');
    });
</script>
</body>
</html>
